package com.employees.action;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.employees.bean.Employee;
import com.employees.bean.EmployeeBase;
import com.employees.bean.Employeeinfo;
import com.employees.service.EmployeeService;
import com.employees.service.impl.EmployeeServiceImpl;


public class EmployeeLogin extends Action {

	private EmployeeService EService;

	public EmployeeService getEService() {
		return EService;
	}

	public void setEService(EmployeeService eService) {
		EService = eService;
	}

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		Employee employeeForm = (Employee) form;
		String name = employeeForm.getName();
		String no = employeeForm.getNo();
		Employee e = EService.getEmployee(no, name);
		if (e != null) {
//			List list = EService.findAllEmployee();
//			List arrlist = new ArrayList();
//			Iterator iterator = list.iterator();
//			while (iterator.hasNext()) {
//				Object[] o = (Object[]) iterator.next();
//
//				Employee employee1 = (Employee) o[0];
//				Employeeinfo employeeinfo = (Employeeinfo) o[1];
//
//				EmployeeBase base = new EmployeeBase();
//
//				base.setNo(employee1.getNo().toString());
//				base.setName(employee1.getName().toString());
//				base.setBirth(employeeinfo.getBirth().toString().substring(0,
//						10));
//				base.setSex(employeeinfo.getSex().toString());
//				base.setDepartment(employeeinfo.getDepartment().toString());
//
//				arrlist.add(base);
//				HttpSession session=request.getSession();
//				session.setAttribute("strArr", arrlist);
//			}
			return mapping.findForward("success");
		}else{
			return mapping.findForward("error");
		}
	}
}
